package com.elock.service.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.elock.base.core.entity.Principal;
import com.elock.base.core.service.impl.BaseServiceImpl;
import com.elock.base.core.util.WebUtils;
import com.elock.dao.PcMenuBaseDao;
import com.elock.entity.Member;
import com.elock.entity.PcMenu;
import com.elock.service.MemberService;
import com.elock.service.PcMenuBaseService;

/**
 * Service - 会员等级
 */
@Service("pcMenuBaseServiceImpl")
public class PcMenuBaseServiceImpl extends BaseServiceImpl<PcMenu> implements
		PcMenuBaseService {

	@Resource(name = "pcMenuBaseDao")
	private PcMenuBaseDao pcMenuBaseDao;
	@Resource(name = "memberServiceImpl")
	private MemberService memberService;

	@Override
	@Transactional(readOnly = true)
	public List<PcMenu> getCurrentMenuList(Integer type) {

		List<PcMenu> menus = new ArrayList<PcMenu>();
		Principal principal = WebUtils.getPrincipal();
		if (principal != null) {
			Member storeMember = memberService.find(principal.getId());
			menus = pcMenuBaseDao.findMenuList(storeMember.getId().toString(),
					principal.getCompanyinfoid(), type);
		}
		return menus;
	}

	@Override
	@Transactional(readOnly = true)
	public Integer findMenuCount(Integer type, String code) {

		Integer count = 0;
		Principal principal = WebUtils.getPrincipal();
		if (principal != null) {
			Member storeMember = memberService.find(principal.getId());
			count = pcMenuBaseDao.findMenuCount(storeMember.getId().toString(),
					principal.getCompanyinfoid(), type, code);
		}
		return count;
	}
}